//
//  MainDefaultTbCell.m
//  ZITHER
//
//  Created by weixin on 2018/7/23.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainDefaultTbCell.h"
#import "GoodsModel.h"

@implementation MainDefaultTbCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.View setCornerRadiusWithRadius:15 isMasks:YES];
    [self.View setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:0.5];
    self.official.textColor = [UIColor blackColor];
    self.secondHandPrices.textColor = baseColorTheme;
    self.pribbabilityLab.textColor = baseColorTheme;
    
    self.title.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
//    self.subTitle.font = [UIFont fontWithName:@"CSD-Block-Bold" size:20];

}

-(void)setFollowModel:(FollowGoodsModel *)followModel{
    _followModel = followModel;
    
    if (![followModel.traced isEqualToString:@"false"]) {
        /** 追踪列表 */
        self.subTitle.textColor = baseColorTheme;
    }else{
        self.subTitle.textColor = [UIColor blackColor];
    }
    
    if (followModel.brandNameNative.length==0) {
        self.title.hidden = YES;
    }else{
        self.title.hidden = NO;
        self.title.text = followModel.brandNameNative;
    }
    
    if (followModel.goodName.length==0) {
        self.subTitle.hidden = YES;
    }else{
        self.subTitle.text = followModel.goodName;
        self.subTitle.hidden = NO;
    }
    
    if (followModel.conjuncturePrice.length==0) {
        self.official.hidden = YES;
        self.officialLab.hidden = YES;
    }else{
        self.official.hidden = NO;
        self.officialLab.hidden = NO;
        self.official.text = followModel.conjuncturePrice;
    }
    
    if (followModel.price.length==0) {
        self.secondHandPrices.hidden = YES;
        self.secondHandLab.hidden = YES;
    }else{
        self.secondHandPrices.hidden = NO;
        self.secondHandLab.hidden = NO;
        self.secondHandPrices.text = followModel.price;
    }
    
    int officialPriceeInt = [followModel.conjuncturePrice intValue];
    
    if (officialPriceeInt == 0) {
        self.official.hidden = YES;
        self.officialLab.hidden = YES;
    }else{
        self.official.hidden = NO;
        self.officialLab.hidden = NO;
        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
        moneyFormatter.positiveFormat = @"###,##0";
        NSString *formatString = [moneyFormatter stringFromNumber:@(officialPriceeInt)];
        self.official.text = formatString;
    }
    
    //    NSArray *arr = model.goodInfo.secondHandPrices;
    int priceInt = [followModel.price intValue];
    
    if (priceInt == 0) {
        self.secondHandPrices.hidden = YES;
        self.secondHandLab.hidden = YES;
    }else{
        self.secondHandPrices.hidden = NO;
        self.secondHandLab.hidden = NO;
        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
        moneyFormatter.positiveFormat = @"###,##0";
        NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
        self.secondHandPrices.text = formatString;
    }
    
    NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,followModel.imageDefault];

    [self.img sd_setImageWithURL:[NSURL URLWithString:str]];
    
    if (self.stare == MainDefaultTbCellTypeSelectWatch) {
        self.pribbabilityLab.hidden = NO;
        self.pribbadilityTitle.hidden = NO;
    }else{
        self.pribbabilityLab.hidden = YES;
        self.pribbadilityTitle.hidden = YES;
    }
    
//
}

-(void)setModel:(goodVOsModel *)model{
    
    _model = model;
    
//    if (self.model.predict.length>0) {
//        NSString *price = [self.model.predict substringToIndex:4];
//
//        price = [price substringFromIndex:2];
//       NSArray *arr = [price componentsSeparatedByString:@"0"];
//
//        if (arr.count==0) {
//            self.pribbabilityLab.text = [NSString stringWithFormat:@"%@%%",price];
//        }else{
//            self.pribbabilityLab.text = [NSString stringWithFormat:@"%@%%",arr[0]];
//        }
//
//        self.pribbabilityLab.hidden = NO;
//        self.pribbadilityTitle.hidden = NO;
//    }else{
//    if (self.stare == MainDefaultTbCellTypeSelectWatch) {
        if (self.model.predict.length>0) {
        self.pribbabilityLab.hidden = NO;
        self.pribbadilityTitle.hidden = NO;
        NSString *price = [self.model.predict substringToIndex:4];
        
        price = [price substringFromIndex:2];
        NSArray *arr = [price componentsSeparatedByString:@"0"];
        
        if (arr.count==0) {
            self.pribbabilityLab.text = [NSString stringWithFormat:@"%@%%",price];
        }else{
            self.pribbabilityLab.text = [NSString stringWithFormat:@"%@%%",arr[0]];
        }
    }else{
        self.pribbabilityLab.hidden = YES;
        self.pribbadilityTitle.hidden = YES;
    }
//    }
   
    //traced 是否追踪
    
    if (![model.traced isEqualToString:@"false"]) {
        /** 追踪列表 */
        self.subTitle.textColor = baseColorTheme;
    }else{
        self.subTitle.textColor = [UIColor blackColor];
    }
    
    NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,model.goodInfo.imageDefault];
    NSLog(@"%@",str);
    
    NSString * strTitle = [NSString stringWithFormat:@"%@%@",model.goodInfo.seriesInfo.brand.brandNameNative,model.goodInfo.seriesInfo.seriesNameNative];
    
    if (strTitle==0) {
        self.title.hidden = YES;
    }else{
        self.title.hidden = NO;
        self.title.text = strTitle;
    }
    
    if (model.goodInfo.goodName.length==0) {
        self.subTitle.hidden = YES;
    }else{
        NSLog(@"%@",model.goodInfo.goodName);
        self.subTitle.text =model.goodInfo.goodNameNative;
        self.subTitle.hidden = NO;
    }
    
    int officialPriceeInt = [model.goodInfo.officialPrice intValue];
    
    if (officialPriceeInt == 0) {
        self.official.hidden = YES;
        self.officialLab.hidden = YES;
    }else{
        self.official.hidden = NO;
        self.officialLab.hidden = NO;
        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
        moneyFormatter.positiveFormat = @"###,##0";
        NSString *formatString = [moneyFormatter stringFromNumber:@(officialPriceeInt)];
        self.official.text = formatString;
    }
    
//    NSArray *arr = model.goodInfo.secondHandPrices;
    
    
    int priceInt = [model.goodInfo.secondHandPrice intValue];
    
    if (priceInt == 0) {
        self.secondHandPrices.hidden = YES;
        self.secondHandLab.hidden = YES;
    }else{
        self.secondHandPrices.hidden = NO;
        self.secondHandLab.hidden = NO;
        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
        moneyFormatter.positiveFormat = @"###,##0";
        NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
        
        if (model.goodInfo.goodPrices!=nil && model.goodInfo.goodPrices.count !=0) {
            int goodPrice = [model.goodInfo.goodPrices[0].price intValue];
            
            NSString *goodPricetString = [moneyFormatter stringFromNumber:@(goodPrice)];
            
            self.secondHandPrices.text = [NSString stringWithFormat:@"%@ - %@",formatString,goodPricetString];
        }else{
            self.secondHandPrices.text = formatString;
        }
    }
    
    NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];

     priceInt = [model.goodInfo.secondHandPrice intValue];
    NSString *price1 = @"";
    NSString *price2 = @"";
    
    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price1= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price1 = @"暂无";
    }
    priceInt = [model.goodInfo.secondHandPriceMax intValue];

    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price2= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price2 = @"暂无";
    }
    
    self.secondHandPrices.text = [NSString stringWithFormat:@"￥%@ - ￥%@",price1,price2]; //二手价
    
    [self.img sd_setImageWithURL:[NSURL URLWithString:str]];
}
@end
